# Contributor: Leo <thinkabit.ukim@gmail.com>
# Maintainer: Krassy Boykinov <kboykinov@teamcentrixx.com>
pkgname=libdbusmenu-glib
pkgver=16.04.0
pkgrel=5
pkgdesc="Library for passing menus over DBus"
options="!check" # 3 tests fail on CI
url="https://launchpad.net/libdbusmenu"
arch="all"
license="GPL-3.0-or-later AND LGPL-2.1-or-later AND LGPL-3.0-or-later"
makedepends="automake autoconf libtool glib-dev gobject-introspection-dev
	vala gtk+3.0-dev json-glib-dev intltool gtk-doc"
checkdepends="dbus-test-runner bash xvfb-run"
subpackages="
	$pkgname-dev:_dev
	libdbusmenu-gtk3
	libdbusmenu-gtk3-dev:_gtk3dev
	"
source="https://launchpad.net/libdbusmenu/16.04/$pkgver/+download/libdbusmenu-$pkgver.tar.gz"
builddir="$srcdir/libdbusmenu-$pkgver"

prepare() {
	default_prepare
	autoreconf -fi
}

build() {
	export CFLAGS="$CFLAGS -Wno-error"
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--disable-dumper \
		--disable-static \
		--enable-tests \
		--enable-vala \
		--enable-introspection \
		HAVE_VALGRIND_FALSE=''
	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install
	rm -rf "$pkgdir"/usr/share/gtk-doc
	rm -rf "$pkgdir"/usr/share/doc
	rm -rf "$pkgdir"/usr/libexec
}

_dev() {
	default_dev

	mkdir -p "$pkgdir"/usr/include \
		"$pkgdir"/usr/lib/pkgconfig \
		"$pkgdir"/usr/lib \
		"$pkgdir"/usr/share/gir-1.0 \
		"$pkgdir"/usr/share/vala/vapi

	mv "$subpkgdir"/usr/include/libdbusmenu-gtk3-* "$pkgdir"/usr/include
	mv "$subpkgdir"/usr/lib/pkgconfig/dbusmenu-gtk3-*.pc "$pkgdir"/usr/lib/pkgconfig
	mv "$subpkgdir"/usr/lib/libdbusmenu-gtk3.so "$pkgdir"/usr/lib
	mv "$subpkgdir"/usr/share/gir-1.0/DbusmenuGtk3-*.gir "$pkgdir"/usr/share/gir-1.0
	mv "$subpkgdir"/usr/share/vala/vapi/DbusmenuGtk3-*.vapi "$pkgdir"/usr/share/vala/vapi
}

gtk3() {
	pkgdesc="$pkgdesc (GTK+3)"

	mkdir -p "$subpkgdir"/usr/lib "$subpkgdir"/usr/lib/girepository-1.0
	mv "$pkgdir"/usr/lib/libdbusmenu-gtk3.so.* "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/girepository-1.0/DbusmenuGtk3-*.typelib \
		"$subpkgdir"/usr/lib/girepository-1.0
}

_gtk3dev() {
	pkgdesc="$pkgdesc (GTK+3)"
	depends_dev="libdbusmenu-glib-dev=$pkgver-r$pkgrel gtk+3.0-dev
		gdk-pixbuf-dev"
	default_dev
}

sha512sums="
ee9654ac4ed94bdebc94a6db83b126784273a417a645b2881b2ba676a5f67d7fc95dd2bb37bfb0890aa47299ed73cb21ed7de8b75f3fed6b69bfd39065062241  libdbusmenu-16.04.0.tar.gz
"
